package justtry;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * Created by weishaofei on 2017/12/9.
 */
public class DuoThread {


    public static class MyTask implements Callable<Integer>{
        public Integer call() throws Exception {
            Thread.sleep(10 * 1000);
            return 1;
        }
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService threadPool = Executors.newCachedThreadPool();
        List<Future<Integer>> tasks = new ArrayList();
        for (int index = 0; index < 100;index ++){
            tasks.add(threadPool.submit(new MyTask()));
        }
        int sum = 0;
        for (Future<Integer> future : tasks){
            System.out.println("current sum is " + sum);
            sum+=future.get();
        }
        System.out.println("final sum is " + sum);
    }
}
